import DefaultAvatar from '@/assets/images/avatar-default.png'

export const defaultAvatar = (e) => {
    if (e?.target?.src) {
        return e.target.src = DefaultAvatar
    }
    return ''
};

export const formatTime = (date = new Date(), format = 'YYYY-MM-DD HH:mm:ss') => {
    const padStart = (value) => (value + '').padStart(2, '0');
    const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    const days = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'];

    const year = date.getFullYear();
    const month = months[date.getMonth()];
    const day = days[date.getDate() - 1];
    const hour = padStart(date.getHours());
    const minute = padStart(date.getMinutes());
    const second = padStart(date.getSeconds());

    return format
        .replace('YYYY', year)
        .replace('MM', month)
        .replace('DD', day)
        .replace('HH', hour)
        .replace('mm', minute)
        .replace('ss', second);
};